package com.wyx.controller;

import com.aliyuncs.exceptions.ClientException;
import com.wyx.pojo.Result;
import com.wyx.utils.AliOssUtil;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Validated
@RestController
@RequestMapping("/other")
public class FileUploadController {
    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws IOException, ClientException {
        String originalFilename = file.getOriginalFilename();
        String fileName= UUID.randomUUID() +originalFilename.substring(originalFilename.lastIndexOf("."));
//        file.transferTo(new File("D:\\Users\\WYX\\Documents\\GitHub\\SpringBoot\\SpringBoot\\BlogSystem\\file\\"+fileName));
        return Result.success(AliOssUtil.upload(fileName,file.getInputStream()));
    }
}
